//
//  ZYMasterViewController.m
//  commonProject
//
//  Created by 飞奔的羊 on 16/6/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "ZYMasterViewController.h"
#import "ZYTabBarViewController.h"
#import "ZYButton.h"
@interface ZYMasterViewController ()
@property (weak, nonatomic) IBOutlet UIView *containerView;

/**
 *  <#Description#>
 */
@property (nonatomic,strong)ZYTabBarViewController *tabbarVc;
/**
 *  <#Description#>
 */
@property (nonatomic,strong)UIStackView *bottomStackView;
/**
 *  <#Description#>
 */
@property (nonatomic,strong)UIStackView *menuStackView;
@end

@implementation ZYMasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	//把 tabbarVC 添加到当前的 masterVC 控制器里面去
	self.tabbarVc = [[ZYTabBarViewController alloc]init];
	[self.view addSubview:self.tabbarVc.view];
	[self addChildViewController:self.tabbarVc];
	
	self.containerView = self.tabbarVc.view;
	
//	[self addBottomStackView];
	[self addMenuStackView];
}
- (void)addMenuStackView
{
	
	[self.menuStackView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.right.mas_equalTo(self.view);
		make.bottom.mas_equalTo(self.bottomStackView.mas_top);
		make.height.mas_equalTo(self.menuStackView.subviews.count * 44);
	}];
	self.menuStackView.distribution = UIStackViewDistributionFillEqually;
	self.menuStackView.axis = UILayoutConstraintAxisVertical;

//给 menuStackView 设置属性
	NSArray *menuData = @[
							@{@"title":@"全部动态"},
							@{@"title":@"与我有关"},
							@{@"title":@"照片墙"},
							@{@"title":@"电子相册"},
							@{@"title":@"好友"},
							@{@"title":@"更多"},
							@{@"title":@"说说",@"bottomStack":@YES},
							@{@"title":@"照片",@"bottomStack":@YES},
							@{@"title":@"日志",@"bottomStack":@YES}
							];
	for (NSDictionary *dict in menuData) {
		ZYButton *button = [ZYButton buttonWithDict:dict];
		
		if (dict[@"bottomStack"]) {
			//bottomStackView
			
		[self.bottomStackView addArrangedSubview:button];
		} else {
		//menuStackView
		
			[self.menuStackView addArrangedSubview:button];
		}
		
	}

}
//判断是否是竖屏
- (void)changePortraitUI:(BOOL)isPortrait
{
	if (isPortrait) {
		//竖屏
		self.bottomStackView.axis = UILayoutConstraintAxisVertical;
		[self.bottomStackView mas_updateConstraints:^(MASConstraintMaker *make) {
			make.height.mas_equalTo(100);
		}];
	} else {
	//横屏
		self.bottomStackView.axis =  UILayoutConstraintAxisHorizontal;
	}
}

//- (void)addBottomStackView
//{
//	[self.bottomStackView mas_makeConstraints:^(MASConstraintMaker *make) {
//		make.left.mas_equalTo(self.view);
//		make.bottom.mas_equalTo(self.view);
//		make.right.mas_equalTo(self.view);
//		make.height.mas_equalTo(44);
//	}];
//	self.bottomStackView.distribution = UIStackViewDistributionFillEqually;
//	
////添加 stackView 里的子控件
//	NSArray *bottomData = @[
//							@{@"title":@"说说"},
//							@{@"title":@"照片"},
//							@{@"title":@"日志"}
//							];
//	for (NSDictionary *dict in bottomData) {
//		UIButton *btn = [[UIButton alloc]init];
//		[btn setTitle:dict[@"title"] forState:UIControlStateNormal];
//		[self.bottomStackView addArrangedSubview:btn];
//	}
//
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIStackView *)bottomStackView
{
	if (_bottomStackView == nil) {
		_bottomStackView = [[UIStackView alloc]init];
		[self.view addSubview:_bottomStackView];
			[self.bottomStackView mas_makeConstraints:^(MASConstraintMaker *make) {
				make.left.mas_equalTo(self.view);
				make.bottom.mas_equalTo(self.view);
				make.right.mas_equalTo(self.view);
				make.height.mas_equalTo(44);
			}];
	}
	return _bottomStackView;
}
- (UIStackView *)menuStackView
{
	if (_menuStackView == nil) {
		_menuStackView = [[UIStackView alloc]init];
		[self.view addSubview:_menuStackView];
	}
	return _menuStackView;
}
- (void)isShowContainerViews:(BOOL)show
{
	self.containerView.hidden = !show;

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
